package com.xyy.saas.payment.query.core.trade;

import com.xyy.saas.payment.cores.enums.TransactionTypeEnum;
import com.xyy.saas.payment.query.core.trade.impl.DefaultTransactionQuery;
import com.xyy.saas.payment.util.SpringUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TransactionQueryFactory {

    private static final Map<String, TransactionQuery> CONCURRENT_HASH_MAP = new ConcurrentHashMap<>();
    private static final TransactionQuery DEFAULT_TRANSACTION_QUERY = new DefaultTransactionQuery();

    static {
        CONCURRENT_HASH_MAP.put(TransactionTypeEnum.PAY.getCode(), SpringUtils.getBean("transactionPayQuery", TransactionQuery.class));
        CONCURRENT_HASH_MAP.put(TransactionTypeEnum.REFUND.getCode(), SpringUtils.getBean("transactionRefundQuery", TransactionQuery.class));
        CONCURRENT_HASH_MAP.put(TransactionTypeEnum.WITHDRAW.getCode(), SpringUtils.getBean("transactionWithdrawQuery", TransactionQuery.class));
    }

    public static TransactionQuery getTransactionQuery(String type) {
        return CONCURRENT_HASH_MAP.getOrDefault(type, DEFAULT_TRANSACTION_QUERY);
    }

}
